home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1990-10-22 | 4.6 KB | 125 lines | [ TEXT/PJMM]
{****************************************************} {} { CFontSizeDial.p } {} { Dialog object to handle user font size selection. } {} { Copyright © 1990, Stanley Fertig. All rights reserved. } {} {****************************************************} unit CFontSizeDial; {Object for choose-your-own fontSize dialog box} interface uses TCL, sfCL, LottoIntf; {----------------------------------------------------------------------------} implementation const EditBoxNumber = 5; {----------------------------------------------------------------------------} procedure CFontSizeDial.IDialog (DIALid: integer; aFloating: Boolean; anEnclosure: CDesktop; aSupervisor: CBureaucrat; Beep, DoCenter: boolean); var {procedure to initialize the dialog object} theType: integer; theItemHandle: Handle; theBox: Rect; aSize: integer; aTextInfo: TextInfoRec; begin if member(aSupervisor, CFontDocument) then {make sure the document uses Fonts...} begin inherited IDialog(DIALid, aFloating, anEnclosure, aSupervisor, Beep, DoCenter); {initialize the standard dialog object, using the appropriate resource #} CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).GetTextInfo(aTextInfo); {get Text Environment of Document} with aTextInfo do aSize := theSize; {Initialize text box to existing font size.} GetDItem(Self.macPort, EditBoxNumber, theType, theItemHandle, theBox); {Get textbox} SetIText(theitemHandle, stringof(aSize : 1)); {change number to string} SelIText(Self.macPort, EditBoxNumber, kSelStart, kSelEnd) {Put string in textbox} end else {if the Document doesn't use fonts, then just beep.} Sysbeep(1) end; {----------------------------------------------------------------------------} function CFontSizeDial.Filter (thedial: DialogPtr; var anEvent: EventRecord; var itemNumber: integer): boolean; var chCode: integer; ch: char; cmdDown: boolean; begin if anEvent.what in [keydown, AutoKey] then begin Filter := true; with anEvent do begin chCode := BitAnd(message, CharCodeMask); ch := chr(chCode); cmdDown := (BitAnd(modifiers, CmdKey) <> 0) end; if not cmdDown then begin if (chCode in [$8, $9, $3, $D, $30..$39]) then {List your 'Acceptable' keys here} Filter := inherited Filter(thedial, anEvent, itemNumber) else begin Sysbeep(1); itemNumber := 0; end end else {if Command Key is down} Filter := inherited Filter(thedial, anEvent, itemNumber) end else {if not Keyboard Event} Filter := inherited Filter(thedial, anEvent, itemNumber) end; {----------------------------------------------------------------------------} procedure CFontSizeDial.DoAlert; {After dialog is on screen, get user response.} const maxSize = 200; {arbitrary largest font size we accept} CancelButton = 3; var theItem: integer; theItemHandle: Handle; theType: integer; theBox: Rect; oldValue: integer; theString: str255; aTextInfo: TextInfoRec; begin InitCursor; repeat ModalDialog(@DialFilter, theItem); {Use customized filter procedure} until theItem in [AltcmdQuit, OK, CancelButton]; {User clicked in either OK or Cancel buttons, or typed command-Q} if theItem = OK then {Clicked in OK button} begin GetDItem(Self.macPort, EditBoxNumber, theType, theItemHandle, theBox); {Get handle to text box} GetIText(theitemHandle, theString); {Get text in textbox} oldValue := IntVal(theString); {Convert text to integer} if (oldValue in [1..maxSize]) then {Acceptable integer?} begin CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).GetTextInfo(aTextInfo); with aTextInfo do theSize := oldValue; {Change font size in Environment record} CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).SetTextInfo(aTextInfo); {Save changed Environment record} CStaticText(CFontDocument(itsSupervisor).itsMainPane).SetFontSize(oldValue) {Change font size in Static Text record} end else {if integer not within acceptable range then beep} Sysbeep(1) end; Self.Free; {Get rid of Dialog & Object} if theItem = AltcmdQuit then {Did User type Command-Q? if so, then Quit Application.} gApplication.DoCommand(cmdQuit) end; {----------------------------------------------------------------------------} end.